from tests.rypark_background.get_cookie import *
from common.config import *
import requests


class Shop:
    # 修改商户充值单价
    def chang_price(self, env, chargePrice, id):
        base_url = getconf(env, "rypark_url")
        url = base_url + "/easypark-backend/shop/changeShopPrice"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": shop_cookies(env)}
        dict = {"chargePrice": chargePrice,
                "id": id}
        return requests.post(url, headers=headers, json=dict).json()

    # 新建商户
    def create_shop(self, env, name, needLimit, freeNumAuto=None, freeRate=None, freeRateDay=None):
        base_url = getconf(env, "rypark_url")
        url = base_url + "/easypark-backend/shop/addShop"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": shop_cookies(env)}
        dict = {"freeNumAuto": freeNumAuto,
                "freeRate": freeRate,
                "freeRateDay": freeRateDay,
                "name": name,
                "needLimit": needLimit,
                "reduceType": 1,
                "shopType": 0,
                "couponOut": 1}
        return requests.post(url, headers=headers, json=dict).json()

    # 修改商户
    def update_shop(self, env, id, name, freeNumAuto=None, freeRate=None, freeRateDay=None):
        base_url = getconf(env, "rypark_url")
        url = base_url + "/easypark-backend/shop/updateShop"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": shop_cookies(env)}
        dict = {"freeNumAuto": freeNumAuto,
                "freeRate": freeRate,
                "freeRateDay": freeRateDay,
                "id": id,
                "manager": "",
                "name": name,
                "needLimit": 0,
                "phone": "",
                "reduceType": 0,
                "returnType": 0,
                "shopAddress": "",
                "couponOut": 1}
        return requests.post(url, headers=headers, json=dict).json()

    # 商户 停用/启用
    # status:1:停用，0:启用
    def change_shop(self, env, id, status):
        base_url = getconf(env, "rypark_url")
        url = base_url + "/easypark-backend/shop/changeShopStatus"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": shop_cookies(env)}
        dict = {"id": id, "status": status}
        return requests.post(url, headers=headers, json=dict).json()

    # 商户后台充值
    def recharge_shop(self, env, shopId, chargeType, chargeNum, chargeDesc=None):
        base_url = getconf(env, "rypark_url")
        url = base_url + "/easypark-backend/shop/shopRecharge"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": shop_cookies(env)}
        dict = {"chargeDesc": chargeDesc,
                "chargeNum": chargeNum,
                "chargeType": chargeType,
                "shopId": shopId}
        return requests.post(url, headers=headers, json=dict).json()

    # 新建商户发券账号
    def create_shop_account(self, env, account, password, confirmPassword, sendType, shopId):
        base_url = getconf(env, "rypark_url")
        url = base_url + "/easypark-backend/parkUser/addShopAccount"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": shop_cookies(env)}
        dict = {"account": account,
                "confirmPassword": confirmPassword,
                "password": password,
                "scanType": 3,
                "sendType": sendType,
                "shopId": shopId,
                "userType": 2}
        return requests.post(url, headers=headers, json=dict).json()

    # 查询商户的发券账号
    def select_shop_account(self, env, shopId):
        base_url = getconf(env, "rypark_url")
        url = base_url + "/easypark-backend/parkUser/selectShopAccount"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": shop_cookies(env)}
        dict = {"shopId": shopId}
        return requests.post(url, headers=headers, json=dict).json()

    # 删除发券商户账号
    def delete_shop_account(self, env, accountId, shopId):
        base_url = getconf(env, "rypark_url")
        url = base_url + "/easypark-backend/parkUser/deleteShopAccount"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": shop_cookies(env)}
        dict = {"accountId": accountId,
                "shopId": shopId}
        return requests.post(url, headers=headers, json=dict).json()

    # 重置商户发券账号密码
    def reset_shop_account(self, env, id, password, confirmPassword):
        base_url = getconf(env, "rypark_url")
        url = base_url + "/easypark-backend/parkUser/resetShopPass"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": shop_cookies(env)}
        dict = {"id": id,
                "password": password,
                "confirmPassword": confirmPassword}
        return requests.post(url, headers=headers, json=dict).json()

    # =====================商户后台=====================
    # 商户后台 充值记录
    def shop_recharge_list(self, env, chargeType='', orderNo='', shopName='',
                           source='', createAtStart='', createAtEnd=''):
        base_url = getconf(env, "rypark_url")
        url = base_url + "/easypark-backend/recharge/selectRechargePageBs"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": shop_cookies(env)}
        dict = {"chargeType": chargeType,
                "createAtStart": createAtStart,
                "createAtEnd": createAtEnd,
                "orderNo": orderNo,
                "shopName": shopName,
                "source": source}
        return requests.post(url, headers=headers, json=dict).json()

    # 商户后台获取商户列表
    def shop_selectpage(self, env, name=None, status=None):
        base_url = getconf(env, "rypark_url")
        url = base_url + "/easypark-backend/shop/selectByPageBs"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": shop_cookies(env)}
        dict = {"name": name, "status": status}
        return requests.post(url, headers=headers, json=dict).json()

    # 商户后台查询商户详情
    def shop_shop_detail(self, env, id):
        base_url = getconf(env, "rypark_url")
        url = base_url + "/easypark-backend/shop/selectDetailBs"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": shop_cookies(env)}
        dict = {"id": id}
        return requests.post(url, headers=headers, json=dict).json()

    # =====================内部后台=====================
    # 运营后台 充值记录
    def internal_recharge_list(self, env, chargeType='', orderNo='', shopName='',
                               parkName='', source='', createAtStart='', createAtEnd=''):
        base_url = getconf(env, "rypark_url")
        url = base_url + "/easypark-backend/recharge/selectRechargePage"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        dict = {"chargeType": chargeType,
                "createAtStart": createAtStart,
                "createAtEnd": createAtEnd,
                "orderNo": orderNo,
                "shopName": shopName,
                "parkName": parkName,
                "source": source}
        return requests.post(url, headers=headers, json=dict).json()

    # 运营后台获取商户列表
    def internal_selectpage(self, env, name=None, parkName=None, status=None):
        base_url = getconf(env, "rypark_url")
        url = base_url + "/easypark-backend/shop/selectByPage"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        dict = {"name": name, "parkName": parkName, "status": status}
        return requests.post(url, headers=headers, json=dict).json()

    # 运营后台查询商户详情
    def internal_shop_detail(self, env, id):
        base_url = getconf(env, "rypark_url")
        url = base_url + "/easypark-backend/shop/selectDetail"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        dict = {"id": id}
        return requests.post(url, headers=headers, json=dict).json()
